/**
 * 
 */
package badugi;

import java.util.ArrayList;
import java.util.Collections;

/**
 * @author aleks
 *
 */
public class Pack {
	private ArrayList<Card> pack;
	private ArrayList<Card> packOfRejectedCards;
	
	Pack() {
		pack = new ArrayList<Card>();
		packOfRejectedCards = new ArrayList<Card>();
		try {
			for (int i=1; i<=4; i++) {
				for (int j=1; j<=13; j++) {
					pack.add(new Card(i,j));
				}
			}
		}
		catch (CardException e) {
			e.getMessage();
		}
	}
	
	public Card giveMeOneCard() {
		if (pack.isEmpty()) {
			int lenghtOfPackOfRejectedCards = packOfRejectedCards.size();
			for (int i = 0; i < lenghtOfPackOfRejectedCards ; i++) {
				pack.add(packOfRejectedCards.remove(0));
			}
			shufflePack();
		}
		return pack.remove(0);
	}
	
	public Card changeOneCard(Card oldCard) {
		packOfRejectedCards.add(oldCard);
		return giveMeOneCard();
	}
	
	/**
	 * @author aleks
	 * This method shuffle the pack by using Collections.shuffle method.
	 */
	public void shufflePack() {
		Collections.shuffle(pack);
	}
	
	/**
	 * @author aleks
	 * Method which enable some tests
	 */
	public ArrayList<Card> getPack() {
		return pack;
	}
	
	public ArrayList<Card> getPackOfRejectedCards() {
		return packOfRejectedCards;
	}
}
